/* javascript for views_bug/list.html */

/* 切换项目 */
function change_project() {
    var req = new Chujue_Request();
    req.url = "/bug/change-project";
    req.send_data = {
        "proj_id": $("#sel-project").val()
    };
    req.pre_check = false;
    req.ok_func = function(data) {
        init_datatbles();
    };
    req.ajax_req();
}

/* 初始化 4 个BUG分类的 tables */
function init_datatbles() {
    $('#dt-created-bugs').dataTable({
        "bProcessing": false,
        "bSort": false,
        // "bFilter": true, // search 框, 默认 true
        // "bLengthChange": true, //修改每页显示的个数, 默认 true
        "sAjaxSource": '/bug/created-bugs',
        "sServerMethod": "POST",
        "bDestroy": true, // 防止重新 init 时出错
        "fnServerParams": function(aoData) {
            aoData.push({
                "name": "proj_id",
                "value": $("#sel-project").val()
            });
        },
    });

    $('#dt-assigning-bugs').dataTable({
        "bProcessing": false,
        "bSort": false,
        "sAjaxSource": '/bug/assigning-bugs',
        "sServerMethod": "POST",
        "bDestroy": true, // 防止重新 init 时出错
        "fnServerParams": function(aoData) {
            aoData.push({
                "name": "proj_id",
                "value": $("#sel-project").val()
            });
        },
    });

    $('#dt-confirming-bugs').dataTable({
        "bProcessing": false,
        "bSort": false,
        "sAjaxSource": '/bug/confirming-bugs',
        "sServerMethod": "POST",
        "bDestroy": true, // 防止重新 init 时出错
        "fnServerParams": function(aoData) {
            aoData.push({
                "name": "proj_id",
                "value": $("#sel-project").val()
            });
        },
    });

    $('#dt-confirmed-bugs').dataTable({
        "bProcessing": false,
        "bSort": false,
        "sAjaxSource": '/bug/confirmed-bugs',
        "sServerMethod": "POST",
        "bDestroy": true, // 防止重新 init 时出错
        "fnServerParams": function(aoData) {
            aoData.push({
                "name": "proj_id",
                "value": $("#sel-project").val()
            });
        },
    });
}

/* 根据bug id 检索bug */
function search_bug() {
    var bug_id = $("#txt-bug-id").val();
    var req = new Chujue_Request();
    req.url = "/bug/search";
    req.send_data = {
        "bug_id": bug_id
    };
    req.ok_func = function(data) {
        var proj_id = data["project_id"];
        location.href = "/bug/edit/" + proj_id + "/" + bug_id;
    };
    req.ajax_req();
}
